<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据来源">
              <j-dict-select-tag placeholder="请选择单据来源" @input="handleDocumentSource" v-model="queryParam.permissionType" dictCode="permission_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 3">
            <a-form-item label="选择部门">
              <J-select-multiple
                placeholder="请选择选择部门"
                :options="getDepartName"
                showId="id"
                v-model="queryParam.deptIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="queryParam.permissionType == 4">
            <a-form-item label="选择团队">
              <J-select-multiple
                placeholder="请选择选择团队"
                :options="getTeamName"
                showId="id"
                v-model="queryParam.teamIds"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号" class="form-item">
              <j-input placeholder="请输入单据编号" v-model="queryParam.billNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称" class="form-item">
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目负责人">
              <select-user-by-dep
                placeholder="请选择项目负责人"
                v-model="queryParam.projectLeading"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目承接人">
              <select-user-by-dep
                placeholder="请选择项目承接人"
                v-model="queryParam.undertaker"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="签订单位">
              <select-company-input v-model="queryParam.signUnit" placeholder="请选择签订单位"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="实施部门" :labelCol="labelCol" :wrapperCol="wrapperCol" class="form-item">
              <j-select-depart v-model="queryParam.executeDepart"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" class="form-item">
              <business-category-select v-model="queryParam.code" @back="handleCategoryNameQuery"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="生产团队">
              <div>
                <select-team-input
                placeholder="请选择生产团队"
                v-model="queryParam.productTeam"
                :tdlx="2"
                :teamType="0"
                :triggerChange="true"/>
              </div>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpReportAudit:add')">新增</a-button>
      <a-button @click="handleCancel" type="primary"  :disabled="isDisabledAuth('erpReportAudit:add')">作废</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('报告审核单')" :disabled="isDisabledAuth('erpReportAudit:export')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpReportAudit:import')">导入</a-button>
      </a-upload>
      -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpReportAudit:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{getCheckboxProps:getCheckboxProps,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="billNo" :title="text" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <span slot="notify" slot-scope="text, record">
          <a-icon title="催办提醒" v-if="record.taskUrge" theme="twoTone" twoToneColor="#eb2f96"
                  @click="taskNotifyMe(flowCode,record.id)" type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
            <template v-if="record.bpmStatus === '1'">
            <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="edit"
                    @click="handleEdit(record)"
                    :disabled="isDisabledAuth('erpReportAudit:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a-button
                        class="ruleButton"
                        :ghost="true"
                        type="primary"
                        icon="delete"
                        :disabled="isDisabledAuth('erpReportAudit:delete')"/>
            </a-popconfirm>
            <!-- <a-divider type="vertical"/>
            <a-button type="primary" size="small" @click="beginProcess(record)" :disabled="isDisabledAuth('erpReportAudit:startProcess')">发起流程</a-button> -->
        </template>
        <template v-else-if="showBtn(record.bpmStatus)&&queryParam.bizTaskType=='1'">
            <a-button type="primary" size="small" @click="handleProcess(record)">办理</a-button>
            <a-divider type="vertical"/>
        </template>
        <template v-else-if="queryParam.bizTaskType=='2' && showBtn(record.bpmStatus)">
            <a-button type="primary" size="small" @click="taskNotify(flowCode,record.id)">催办</a-button>
            <a-divider type="vertical"/>
            <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(record)">
                <a-button type="primary" size="small" :disabled="isDisabledAuth('erpReportAudit:invalidProcess')">
                    作废流程
                </a-button>
            </a-popconfirm>
            <a-divider type="vertical"/>
        </template>
        <template v-if="record.bpmStatus !== '1'">
            <a-button type="primary" size="small" @click="handleTrack(record)" :disabled="isDisabledAuth('erpReportAudit:viewTrack')">审批进度</a-button>
        </template>
        </span>
        <span slot="projectName" :title="text" slot-scope="text,record">
          <a href="javascript:void(0);" @click="goProjectDetail(record)">{{ text }}</a>
        </span>
      </a-table>
    </div>
    <!-- 项目详情开始 -->
    <erp-project-report-modal ref="projectReport"></erp-project-report-modal>
    <erp-report-audit-modal ref="modalForm" @ok="modalFormOk"></erp-report-audit-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData" @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
    <process-config-modal ref="processConfig" isAfterStart="1" isCheck="1" @ok="handleSuccess" @close="handleClose"></process-config-modal>
  </a-card>
</template>
<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import {JeecgBpmListMixin} from '@/mixins/JeecgBpmListMixin'
  import BpmBizTaskDealModal from "@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue";
  import BpmProcessTrackModal from "@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue";
  import BizTaskNotifyModal from "@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue";
  import BizTaskNotifyMeModal from "@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue";
  import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
  import ErpReportAuditModal from './modules/ErpReportAuditModal'
  import { getAction } from '@/api/manage'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import BusinessCategorySelect from "../../components/BusinessCategoryNameSelect.vue";
  export default {
    name: 'ErpReportAuditList',
    mixins:[JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      BusinessCategorySelect,
      ErpProjectReportModal: () => import('@/views/erp/report/project/modules/ErpProjectReportModal'),
      ErpReportAuditModal,
      BpmBizTaskDealModal,
      BpmProcessTrackModal,
      BizTaskNotifyModal,
      BizTaskNotifyMeModal,
      ProcessConfigModal,
      SelectUserByDep,
      SelectProjectInput,
      SelectCompanyInput,
      SelectTeamInput
    },
    data () {
      return {
        description: '报告审核单管理页面',
        //表头
        columns:[],
        labelCol: {},
        //列设置
        settingColumns:[],
        queryParam: {},
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '单据编号',
            align: 'center',
            dataIndex: 'billNo',
            width:200,
            scopedSlots: { customRender: 'billNo' },
            ellipsis: true
          },
          {
            title: '申请人',
            align: 'center',
            dataIndex: 'handlerId_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title: '申请部门',
            align: 'center',
            dataIndex: 'handlerDeptId_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title: '项目名称',
            align: 'center',
            dataIndex: 'projectId_dictText',
            scopedSlots: { customRender: 'projectName' },
            ellipsis: true,
            width: 146,
          },
          {
            title:'项目负责人',
            align:"center",
            dataIndex: 'projectLeading_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title:'生产团队',
            align:"center",
            dataIndex: 'productTeam_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title:'实施部门',
            align:"center",
            dataIndex: 'executeDepart_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title:'签订单位',
            align:"center",
            dataIndex: 'signUnit_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title:'业务名称',
            align:"center",
            dataIndex: 'categoryName',
            ellipsis: true,
            width: 146,
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'bpmStatus_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title:'单据类型',
            align:"center",
            dataIndex: 'billType_dictText',
            ellipsis: true,
            width: 146,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:160,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/omc/reportaudit/erpReportAudit/list",
          delete: "/api/erp/omc/reportaudit/erpReportAudit/delete",
          deleteBatch: "/api/erp/omc/reportaudit/erpReportAudit/deleteBatch",
          exportXlsUrl: "/api/erp/omc/reportaudit/erpReportAudit/exportXls",
          importExcelUrl: "/api/erp/omc/reportaudit/erpReportAudit/importExcel",
          bizCount: "/api/erp/omc/reportaudit/erpReportAudit/bizCount",
          // 穿透项目底表
          queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
          startProcess: '/api/erpmng/act/process/activiti/startMutilProcessCanBack'
        },
        //代码生成后需手动设置流程编码
        flowCode: 'onl_erp_report_audit',
        formUrl: "/erp/omc/reportaudit/modules/ErpReportAuditForm",
        formUrlMobile: "/pages/synergy/ErpReportAuditForm",
        beanName:"ErpReportAuditFlow",
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      // model,
      //发起流程
      beginProcess(record){
        // 判断是否在变更中
        getAction('/api/erp/omc/project/erpOmcProjectTask/checkTaskChangeById', { id: record.taskId }).then(res => {
          if (res.success) {
            console.log(res,'孙康-----');
            this.$refs.processConfig.visible = true
            this.$refs.processConfig.formUrl = this.formUrl
            this.$refs.processConfig.formUrlMobile = this.formUrlMobile
            this.$refs.processConfig.flowCode = this.flowCode
            // 自动验证流程
            this.$refs.processConfig.url.startProcess = this.url.startProcess
            this.$refs.processConfig.edit(record,'',this.beanName)
          } else {
            this.$message.warning(res.message)
            this.handleClose()
          }
        })
      },
      handleAdd () {
        this.$refs.modalForm.add('apply'); // 申请
        this.$refs.modalForm.title = '新增';
        this.$refs.modalForm.disableSubmit = false;
        this.flowCode = 'onl_erp_report_audit'
        this.beanName = 'ErpReportAuditFlow'
      },
      handleTrack(record) {
        if(record.billNo && record.billNo.substring(0, 2) == 'ZF') {
        this.flowCode = 'dev_erp_report_audit_001'
        this.beanName = 'ErpReportAuditCancelFlow'
      } else {
        this.flowCode = 'onl_erp_report_audit'
        this.beanName = 'ErpReportAuditFlow'
      }
      var params = { flowCode: this.flowCode, dataId: record.id };// 查询条件
      this.$refs.bpmProcessTrackModal.handleTrack(params);
      this.$refs.bpmProcessTrackModal.title = '审批跟踪记录';
    },
    handleEdit (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = '编辑';
      this.$refs.modalForm.disableSubmit = false;
      if(record.billNo && record.billNo.substring(0, 2) == 'ZF') {
        this.flowCode = 'dev_erp_report_audit_001'
        this.beanName = 'ErpReportAuditCancelFlow'
      } else {
        this.flowCode = 'onl_erp_report_audit'
        this.beanName = 'ErpReportAuditFlow'
      }
    },
      handleCancel(){
        this.$refs.modalForm.add('cancel'); // 
        this.$refs.modalForm.title = '作废';
        this.$refs.modalForm.disableSubmit = false;
        this.flowCode = 'dev_erp_report_audit_001'
        this.beanName = 'ErpReportAuditCancelFlow'
      },
      //查看详情
      getDetail(id) {
        this.$router.push({
          path: `/reportaudit/ErpReportAuditListDetail/${id}`,
        })
      },
      initDictConfig(){
      },
      handleCategoryNameQuery(data){
        this.queryParam.categoryName = data.categoryName
      },
      // 列表页穿透项目底表
      goProjectDetail(record) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectReportById, { id: record.projectId }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectReport.getDetail(model);
              that.$refs.projectReport.title = '项目一览表';
            }
          })
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'projectName',text:'项目名称',dictCode:''})
        fieldList.push({type:'string',value:'projectId',text:'项目id',dictCode:''})
        fieldList.push({type:'string',value:'finalNo',text:'项目档案',dictCode:''})
        fieldList.push({type:'string',value:'taskId',text:'关联任务',dictCode:''})
        fieldList.push({type:'string',value:'projectLeading',text:'项目负责人',dictCode:''})
        fieldList.push({type:'string',value:'productTeam',text:'生产团队',dictCode:''})
        fieldList.push({type:'string',value:'executeDepart',text:'实施部门',dictCode:''})
        fieldList.push({type:'string',value:'qualificationUnit',text:'资质单位',dictCode:''})
        fieldList.push({type:'string',value:'signUnit',text:'签订单位',dictCode:''})
        fieldList.push({type:'string',value:'areaCode',text:'项目地址',dictCode:''})
        fieldList.push({type:'string',value:'projectAddress',text:'详细地址',dictCode:''})
        fieldList.push({type:'string',value:'industryCategory',text:'行业类别',dictCode:'industry_category'})
        fieldList.push({type:'string',value:'industryCoefficient',text:'行业系数',dictCode:''})
        fieldList.push({type:'string',value:'approvalLevel',text:'审批类别',dictCode:'approval_level'})
        fieldList.push({type:'string',value:'approvalCoefficient',text:'审批系数',dictCode:''})
        fieldList.push({type:'string',value:'complexity',text:'复杂程度',dictCode:''})
        fieldList.push({type:'string',value:'complexCoefficient',text:'复杂系数',dictCode:''})
        fieldList.push({type:'Text',value:'projectResult',text:'项目成果',dictCode:'review_result'})
        fieldList.push({type:'Text',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'engineerSecondReview',text:'工程师（二审）',dictCode:''})
        fieldList.push({type:'string',value:'engineerThirdReview',text:'工程师（三审）',dictCode:''})
        fieldList.push({type:'string',value:'reviewResult',text:'项目评审情况',dictCode:'review_result'})
        fieldList.push({type:'BigDecimal',value:'secondReviewFee',text:'二审审核费',dictCode:''})
        fieldList.push({type:'Text',value:'secondReviewProcess',text:'二审审核费计算过程',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'thirdReviewFee',text:'三审审核费',dictCode:''})
        fieldList.push({type:'string',value:'thirdReviewProcess',text:'三审审核费计算过程',dictCode:''})
        fieldList.push({type:'string',value:'feeTeamId',text:'费用所属团队',dictCode:''})
        fieldList.push({type:'Text',value:'file',text:'任务附件',dictCode:''})
        fieldList.push({type:'string',value:'billNo',text:'单据标号',dictCode:''})
        fieldList.push({type:'string',value:'bpmStatus',text:'流程状态',dictCode:''})
        fieldList.push({type:'string',value:'bpmBizTitle',text:'流程标题',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
